﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net.Mail;
using System.Data.SqlClient;
using System.Collections;
using System.Text.RegularExpressions;
using System.Security;
using System.Data;
namespace StreetSmartAdmin
{


    public partial class MNL_Admin : System.Web.UI.Page
    {
        public static ArrayList maillist;
        protected void Timer1_Tick(object sender, EventArgs e)
        {
            if (DetailsView1.DefaultMode.Equals("Edit"))
                if (DetailsView1.DataItemCount != 0)
                    DetailsView1.UpdateItem(false);
        }

        protected void ExactSearchButton_Click(object sender, EventArgs e)
        {
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            //Session.Add("UserName", UserCap(User.Identity.Name));
            //Userinfo user = (Userinfo)Session["UserInfo"];
            //Session.Add("UserName", user.fullname);
            //Session.Add("LoginName", user.username);
            //Session.Add("Permission", user.permission);
            //((Label)Header.FindControl("lblUser")).Text = ((Userinfo)Session["UserInfo"]).fullname; 
            //((Label)Header.FindControl("lblUser")).Text = ((String)Session["UserName"]);
            ADODotNetCRUD crud = new ADODotNetCRUD();
            Userinfo user = crud.GetUser(User.Identity.Name);
            ((Label)Header.FindControl("lblUser")).Text = (user.fullname);
            if (user.auto)
            {
                ((Label)Header.FindControl("lblGroup")).Text = (user.groupname);
            }
            if (IsPostBack)
            {
                if ((Button7.Visible == false) && (Button6.Visible == true) && (!Label16.Text.Equals("Single")) && SearchDropDownList.SelectedValue.Equals("PromotionCode"))
                    Button9.Visible = true;
                else
                    Button9.Visible = false;
                if (SearchDropDownList.SelectedValue.Equals("PromotionCode"))
                {
                    if (Label5.Text.Equals("First"))
                        GridView1.DataSourceID = "SqlDataSource13";
                    else
                        GridView1.DataSourceID = "SqlDataSource21";
                }
                else if (SearchDropDownList.SelectedValue.Equals("AccountStatus"))
                {
                    if (Label5.Text.Equals("First"))
                        GridView1.DataSourceID = "SqlDataSource12";
                    else
                        GridView1.DataSourceID = "SqlDataSource20";
                }
                else if (SearchDropDownList.SelectedValue.Equals("TypeOrg"))
                {
                    if (Label5.Text.Equals("First"))
                        GridView1.DataSourceID = "SqlDataSource33";
                    else
                        GridView1.DataSourceID = "SqlDataSource34";
                }
                else if (SearchDropDownList.SelectedValue.Equals("StateName"))
                {
                    if (Label5.Text.Equals("First"))
                        GridView1.DataSourceID = "SqlDataSource11";
                    else
                        GridView1.DataSourceID = "SqlDataSource19";

                }
                else if (SearchDropDownList.SelectedValue.Equals("CurrentProvider"))
                {
                    if (Label5.Text.Equals("First"))
                        GridView1.DataSourceID = "SqlDataSource25";
                    else
                        GridView1.DataSourceID = "SqlDataSource28";

                }
                else if (SearchDropDownList.SelectedValue.Equals("OperatorSSE"))
                {
                    if (Label5.Text.Equals("First"))
                        GridView1.DataSourceID = "SqlDataSource2";
                    else
                        GridView1.DataSourceID = "SqlDataSource3";

                }
                else if (SearchDropDownList.SelectedValue.Equals("UserID"))
                {
                    if (SearchTextBox.Text == "")
                        GridView1.DataSourceID = "SqlDataSource0";
                    else
                        GridView1.DataSourceID = "SqlDataSource15";
                }
                else if (SearchDropDownList.SelectedValue.Equals("FirstName"))
                {
                    if (SearchTextBox.Text == "")
                        if (Label5.Text.Equals("First"))
                            GridView1.DataSourceID = "SqlDataSource0";
                        else
                            GridView1.DataSourceID = "SqlDataSource16";
                    else
                        if (Label5.Text.Equals("First"))
                            GridView1.DataSourceID = "SqlDataSource9";
                        else
                            GridView1.DataSourceID = "SqlDataSource17";
                }
                else if (SearchDropDownList.SelectedValue.Equals("LastName"))
                {
                    if (SearchTextBox.Text == "")
                        if (Label5.Text.Equals("First"))
                            GridView1.DataSourceID = "SqlDataSource0";
                        else
                            GridView1.DataSourceID = "SqlDataSource16";
                    else
                        if (Label5.Text.Equals("First"))
                            GridView1.DataSourceID = "SqlDataSource10";
                        else
                            GridView1.DataSourceID = "SqlDataSource18";
                }
                else if (SearchDropDownList.SelectedValue.Equals("Email"))
                {
                    if (SearchTextBox.Text == "")
                        if (Label5.Text.Equals("First"))
                            GridView1.DataSourceID = "SqlDataSource0";
                        else
                            GridView1.DataSourceID = "SqlDataSource16";
                    else
                        if (Label5.Text.Equals("First"))
                            GridView1.DataSourceID = "SqlDataSource14";
                        else
                            GridView1.DataSourceID = "SqlDataSource22";
                }
                else if (SearchDropDownList.SelectedValue.Equals("Phone"))
                {
                    if (SearchTextBox.Text == "")
                        if (Label5.Text.Equals("First"))
                            GridView1.DataSourceID = "SqlDataSource0";
                        else
                            GridView1.DataSourceID = "SqlDataSource16";
                    else
                        if (Label5.Text.Equals("First"))
                            GridView1.DataSourceID = "SqlDataSource23";
                        else
                            GridView1.DataSourceID = "SqlDataSource26";
                }
                else if (SearchDropDownList.SelectedValue.Equals("CompanyName"))
                {
                    if (SearchTextBox.Text == "")
                        if (Label5.Text.Equals("First"))
                            GridView1.DataSourceID = "SqlDataSource0";
                        else
                            GridView1.DataSourceID = "SqlDataSource16";
                    else
                        if (Label5.Text.Equals("First"))
                            GridView1.DataSourceID = "SqlDataSource24";
                        else
                            GridView1.DataSourceID = "SqlDataSource27";
                }
                else if (SearchDropDownList.SelectedValue.Equals("PreferredDay"))
                {
                    if ((Date1.Text == "") || (Date2.Text == ""))
                        if (Label5.Text.Equals("First"))
                            GridView1.DataSourceID = "SqlDataSource0";
                        else
                            GridView1.DataSourceID = "SqlDataSource16";
                    else
                        if (Label5.Text.Equals("First"))
                            GridView1.DataSourceID = "SqlDataSource31";
                        else
                            GridView1.DataSourceID = "SqlDataSource32";
                }
                else if (SearchDropDownList.SelectedValue.Equals("All"))
                {
                    if (SearchTextBox.Text == "")
                        if (Label5.Text.Equals("First"))
                            GridView1.DataSourceID = "SqlDataSource0";
                        else
                            GridView1.DataSourceID = "SqlDataSource16";
                    else
                        if (Label5.Text.Equals("First"))
                            GridView1.DataSourceID = "SqlDataSource29";
                        else
                            GridView1.DataSourceID = "SqlDataSource30";
                }
                else
                {
                    if (Label5.Text.Equals("First"))
                        GridView1.DataSourceID = "SqlDataSource0";
                    else
                        GridView1.DataSourceID = "SqlDataSource16";
                }

            }
            else
            {
                Label5.Text = "Last";
                Label10.Text = "None";
                Label11.Text = "None";
                Label17.Text = "None";
                Label18.Text = "None";
                Label19.Text = "None";
                Date1.Visible = false;
                Date2.Visible = false;
                DropDownList1.Visible = false;
                DropDownList2.Visible = false;
                DropDownList3.Visible = false;
                DropDownList4.Visible = false;
                DropDownList5.Visible = false;
                DropDownList6.Visible = false;
                GridView1.DataSourceID = "SqlDataSource16";
            }
                //GridView1.AllowPaging = false;
                //GridView1.DataBind();
                //Label12.Text = Convert.ToString(GridView1.Rows.Count);
                //GridView1.AllowPaging = true;
                //GridView1.DataBind();

        }


        protected void SearchDropDownList_SelectedIndexChanged(object sender, EventArgs e)
        {
            Label7.Text = "";
            Label8.Text = "";
            if (SearchDropDownList.SelectedValue.Equals("PromotionCode"))
            {
                Date1.Visible = false;
                Date2.Visible = false;
                SearchTextBox.Visible = false;
                DropDownList1.Visible = false;
                DropDownList3.Visible = false;
                DropDownList4.Visible = false;
                DropDownList5.Visible = false;
                DropDownList6.Visible = false;
                DropDownList2.Visible = true;

            }
            else if (SearchDropDownList.SelectedValue.Equals("TypeOrg"))
            {
                Date1.Visible = false;
                Date2.Visible = false;
                SearchTextBox.Visible = false;
                DropDownList1.Visible = false;
                DropDownList2.Visible = false;
                DropDownList3.Visible = false;
                DropDownList4.Visible = false;
                DropDownList6.Visible = false;
                DropDownList5.Visible = true;

            }
            else if (SearchDropDownList.SelectedValue.Equals("OperatorSSE"))
            {
                Date1.Visible = false;
                Date2.Visible = false;
                SearchTextBox.Visible = false;
                DropDownList1.Visible = false;
                DropDownList2.Visible = false;
                DropDownList3.Visible = false;
                DropDownList4.Visible = false;
                DropDownList5.Visible = false;
                DropDownList6.Visible = true;

            }
            else if (SearchDropDownList.SelectedValue.Equals("AccountStatus"))
            {
                Date1.Visible = false;
                Date2.Visible = false;
                SearchTextBox.Visible = false;
                DropDownList2.Visible = false;
                DropDownList3.Visible = false;
                DropDownList4.Visible = false;
                DropDownList5.Visible = false;
                DropDownList6.Visible = false;
                DropDownList1.Visible = true;
            }
            else if (SearchDropDownList.SelectedValue.Equals("StateName"))
            {
                Date1.Visible = false;
                Date2.Visible = false;
                SearchTextBox.Visible = false;
                DropDownList1.Visible = false;
                DropDownList2.Visible = false;
                DropDownList4.Visible = false;
                DropDownList5.Visible = false;
                DropDownList6.Visible = false;
                DropDownList3.Visible = true;
            }
            else if (SearchDropDownList.SelectedValue.Equals("PreferredDay"))
            {
                Label7.Text = "From";
                Label8.Text = "To";
                Date1.Visible = true;
                Date2.Visible = true;
                Date1.Text = "";
                Date2.Text = "";
                SearchTextBox.Visible = false;
                DropDownList1.Visible = false;
                DropDownList2.Visible = false;
                DropDownList3.Visible = false;
                DropDownList4.Visible = false;
                DropDownList5.Visible = false;
                DropDownList6.Visible = false;
            }
            else if (SearchDropDownList.SelectedValue.Equals("CurrentProvider"))
            {
                Date1.Visible = false;
                Date2.Visible = false;
                SearchTextBox.Visible = false;
                DropDownList1.Visible = false;
                DropDownList2.Visible = false;
                DropDownList3.Visible = false;
                DropDownList5.Visible = false;
                DropDownList6.Visible = false;
                DropDownList4.Visible = true;
            }
            else
            {
                Date1.Visible = false;
                Date2.Visible = false;
                DropDownList1.Visible = false;
                DropDownList2.Visible = false;
                DropDownList3.Visible = false;
                DropDownList4.Visible = false;
                DropDownList5.Visible = false;
                DropDownList6.Visible = false;
                SearchTextBox.Visible = true;
                SearchTextBox.Text = "";
            }

        }

        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
        }

        protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
        {
            Button6.Visible = true;
            Button9.Visible = true;
            Button7.Visible = false;
            Button8.Visible = false;
            pnlSelectEmail.Visible = false;
            Label14.Text = "";
        }

        protected void DropDownList3_SelectedIndexChanged(object sender, EventArgs e)
        {
        }

        protected void CreateNew_Click(object sender, EventArgs e)
        {
            if (DetailsView1.FindControl("FirstName") != null)
            {
                Session.Clear();
                Session.Add("FirstName", ((TextBox)DetailsView1.FindControl("FirstName")).Text);
                Session.Add("LastName", ((TextBox)DetailsView1.FindControl("LastName")).Text);
                Session.Add("CompanyName", ((TextBox)DetailsView1.FindControl("CompanyName")).Text);
                Session.Add("CompanyABN", ((TextBox)DetailsView1.FindControl("CompanyABN")).Text);
                Session.Add("Street", ((TextBox)DetailsView1.FindControl("Street")).Text);
                Session.Add("Suburb", ((TextBox)DetailsView1.FindControl("Suburb")).Text);
                Session.Add("StateName", ((TextBox)DetailsView1.FindControl("StateName")).Text);
                Session.Add("Postcode", ((TextBox)DetailsView1.FindControl("Postcode")).Text);
                Session.Add("Phone", ((TextBox)DetailsView1.FindControl("Phone")).Text);
                Session.Add("Mobile", ((TextBox)DetailsView1.FindControl("Mobile")).Text);
                Session.Add("Email", ((TextBox)DetailsView1.FindControl("Email")).Text);
                Session.Add("Comments", ((TextBox)DetailsView1.FindControl("Comments")).Text);
                Session.Add("CurrentProvider", ((TextBox)DetailsView1.FindControl("CurrentProvider")).Text);
                Session.Add("PromotionCode", ((TextBox)DetailsView1.FindControl("PromotionCode")).Text);
                Session.Add("AdminFee", ((TextBox)DetailsView1.FindControl("AdminFee")).Text);
                Session.Add("LeadSource", ((TextBox)DetailsView1.FindControl("LeadSource")).Text);
                Session.Add("TypeOrg", ((TextBox)DetailsView1.FindControl("TypeOrg")).Text);
                Session.Add("PreferredDay", ((TextBox)DetailsView1.FindControl("PreferredDay")).Text);
                Session.Add("PreferredTime", ((TextBox)DetailsView1.FindControl("PreferredTime")).Text);
                Session.Add("TotalSites", ((TextBox)DetailsView1.FindControl("TotalSites")).Text);
                Session.Add("ElecTotalAnnualSpend", ((TextBox)DetailsView1.FindControl("ElecTotalAnnualSpend")).Text);
                Session.Add("GasTotalAnnualSpend", ((TextBox)DetailsView1.FindControl("GasTotalAnnualSpend")).Text);
                Session.Add("TotalAnnualSpend", ((TextBox)DetailsView1.FindControl("TotalAnnualSpend")).Text);
                Session.Add("AccountStatus", ((TextBox)DetailsView1.FindControl("AccountStatus")).Text);
                Session.Add("StatusName", ((TextBox)DetailsView1.FindControl("StatusName")).Text);
                Session.Add("AccountStatusHistory", ((TextBox)DetailsView1.FindControl("AccountStatusHistory")).Text);
                Session.Add("SourceCode", ((TextBox)DetailsView1.FindControl("SourceCode")).Text);
                Session.Add("OperatorSSE", ((TextBox)DetailsView1.FindControl("OperatorSSE")).Text);
                Session.Add("VendorID", ((TextBox)DetailsView1.FindControl("VendorID")).Text);
                Session.Add("DateConverted", ((TextBox)DetailsView1.FindControl("DateConverted")).Text);
                Session.Add("MoverSwicher", ((TextBox)DetailsView1.FindControl("MoverSwicher")).Text);
                Session.Add("RESI_SME", ((TextBox)DetailsView1.FindControl("RESI_SME")).Text);
                Session.Add("ElectricityConversion", ((TextBox)DetailsView1.FindControl("ElectricityConversion")).Text);
                Session.Add("GasConversion", ((TextBox)DetailsView1.FindControl("GasConversion")).Text);
                Session.Add("MoveInDate", ((TextBox)DetailsView1.FindControl("MoveInDate")).Text);
                Session.Add("ID_Type", ((TextBox)DetailsView1.FindControl("ID_Type")).Text);
                Session.Add("ID_Number", ((TextBox)DetailsView1.FindControl("ID_Number")).Text);
                Session.Add("ID_Expiry", ((TextBox)DetailsView1.FindControl("ID_Expiry")).Text);
                Session.Add("AccountHolderCompanyName", ((TextBox)DetailsView1.FindControl("AccountHolderCompanyName")).Text);
                Session.Add("FirstAccountHolderTitle", ((TextBox)DetailsView1.FindControl("FirstAccountHolderTitle")).Text);
                Session.Add("FirstAccountHolderFirstName", ((TextBox)DetailsView1.FindControl("FirstAccountHolderFirstName")).Text);
                Session.Add("FirstAccountHolderSurname", ((TextBox)DetailsView1.FindControl("FirstAccountHolderSurname")).Text);
                Session.Add("FirstAccountHolderDOB", ((TextBox)DetailsView1.FindControl("FirstAccountHolderDOB")).Text);
                Session.Add("SecondAccountHolderTitle", ((TextBox)DetailsView1.FindControl("SecondAccountHolderTitle")).Text);
                Session.Add("SecondAccountHolderFirstName", ((TextBox)DetailsView1.FindControl("SecondAccountHolderFirstName")).Text);
                Session.Add("SecondAccountHolderSurname", ((TextBox)DetailsView1.FindControl("SecondAccountHolderSurname")).Text);
                Session.Add("SecondAccountHolderDOB", ((TextBox)DetailsView1.FindControl("SecondAccountHolderDOB")).Text);
                Session.Add("ContactTel", ((TextBox)DetailsView1.FindControl("ContactTel")).Text);
                Session.Add("SecondTel", ((TextBox)DetailsView1.FindControl("SecondTel")).Text);
                Session.Add("SupplyAddress", ((TextBox)DetailsView1.FindControl("SupplyAddress")).Text);
                Session.Add("SupplyAddressSuburb", ((TextBox)DetailsView1.FindControl("SupplyAddressSuburb")).Text);
                Session.Add("SupplyAddressState", ((TextBox)DetailsView1.FindControl("SupplyAddressState")).Text);
                Session.Add("SupplyAddressPostcode", ((TextBox)DetailsView1.FindControl("SupplyAddressPostcode")).Text);
                Session.Add("TenantOwner", ((TextBox)DetailsView1.FindControl("TenantOwner")).Text);
                Session.Add("Elec", ((TextBox)DetailsView1.FindControl("Elec")).Text);
                Session.Add("Gas", ((TextBox)DetailsView1.FindControl("Gas")).Text);
                Session.Add("ProductType", ((TextBox)DetailsView1.FindControl("ProductType")).Text);
                Session.Add("NoOfPeopleInHouse", ((TextBox)DetailsView1.FindControl("NoOfPeopleInHouse")).Text);
                Session.Add("ConcessionCardType", ((TextBox)DetailsView1.FindControl("ConcessionCardType")).Text);
                Session.Add("ConcessionCardEntitlement", ((TextBox)DetailsView1.FindControl("ConcessionCardEntitlement")).Text);
                Session.Add("ConcessionCardNo", ((TextBox)DetailsView1.FindControl("ConcessionCardNo")).Text);
                Session.Add("ConcessionCardExp", ((TextBox)DetailsView1.FindControl("ConcessionCardExp")).Text);
                Session.Add("NameOnConcessionCard", ((TextBox)DetailsView1.FindControl("NameOnConcessionCard")).Text);
                Session.Add("AnyHazards", ((TextBox)DetailsView1.FindControl("AnyHazards")).Text);
                Session.Add("AnyAccessRequirements", ((TextBox)DetailsView1.FindControl("AnyAccessRequirements")).Text);
                Session.Add("SpecialInstructionsForAccess", ((TextBox)DetailsView1.FindControl("SpecialInstructionsForAccess")).Text);
                Session.Add("AdvisedMainSwitchNeedsTurningOff", ((TextBox)DetailsView1.FindControl("AdvisedMainSwitchNeedsTurningOff")).Text);
                Session.Add("SafetyCertificateRequired", ((TextBox)DetailsView1.FindControl("SafetyCertificateRequired")).Text);
                Session.Add("ElecStatus", ((TextBox)DetailsView1.FindControl("ElecStatus")).Text);
                Session.Add("GasStatus", ((TextBox)DetailsView1.FindControl("GasStatus")).Text);
                Session.Add("Reason", ((TextBox)DetailsView1.FindControl("Reason")).Text);
                Session.Add("ExistingTRUEnergyCustomer", ((TextBox)DetailsView1.FindControl("ExistingTRUEnergyCustomer")).Text);
                Session.Add("AdditionalQuestion", ((TextBox)DetailsView1.FindControl("AdditionalQuestion")).Text);
                Session.Add("SSE_Operator_Feedback", ((TextBox)DetailsView1.FindControl("SSE_Operator_Feedback")).Text);
            }
            DetailsView1.ChangeMode(DetailsViewMode.Insert);
            DetailsView1.AutoGenerateInsertButton = false;
        }

        protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            DetailsView1.ChangeMode(DetailsViewMode.Edit);
        }

        protected void DetailsView1_PageIndexChanging(object sender, DetailsViewPageEventArgs e)
        {

        }

        protected void Edit_Click(object sender, EventArgs e)
        {
            DetailsView1.ChangeMode(DetailsViewMode.Edit);
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            if (SearchDropDownList.SelectedValue.Equals("PromotionCode"))
            {
                GridView1.DataSourceID = "SqlDataSource21";
            }
            else if (SearchDropDownList.SelectedValue.Equals("OperatorSSE"))
            {
                GridView1.DataSourceID = "SqlDataSource3";
            }
            else if (SearchDropDownList.SelectedValue.Equals("AccountStatus"))
            {
                GridView1.DataSourceID = "SqlDataSource20";
            }
            else if (SearchDropDownList.SelectedValue.Equals("TypeOrg"))
            {
                GridView1.DataSourceID = "SqlDataSource34";
            }
            else if (SearchDropDownList.SelectedValue.Equals("StateName"))
            {
                GridView1.DataSourceID = "SqlDataSource19";
            }
            else if (SearchDropDownList.SelectedValue.Equals("CurrentProvider"))
            {
                GridView1.DataSourceID = "SqlDataSource28";
            }
            else if (SearchDropDownList.SelectedValue.Equals("UserID"))
            {
                if (SearchTextBox.Text == "")
                {
                    GridView1.DataSourceID = "SqlDataSource16";
                }
                else
                {
                    GridView1.DataSourceID = "SqlDataSource15";
                }
            }
            else if (SearchDropDownList.SelectedValue.Equals("FirstName"))
            {
                if (SearchTextBox.Text == "")
                    GridView1.DataSourceID = "SqlDataSource16";
                else
                {
                    GridView1.DataSourceID = "SqlDataSource17";
                }
            }
            else if (SearchDropDownList.SelectedValue.Equals("LastName"))
            {
                if (SearchTextBox.Text == "")
                    GridView1.DataSourceID = "SqlDataSource16";
                else
                {
                    GridView1.DataSourceID = "SqlDataSource18";
                }
            }
            else if (SearchDropDownList.SelectedValue.Equals("Email"))
            {
                if (SearchTextBox.Text == "")
                    GridView1.DataSourceID = "SqlDataSource16";
                else
                {
                    GridView1.DataSourceID = "SqlDataSource22";
                }
            }
            else if (SearchDropDownList.SelectedValue.Equals("Phone"))
            {
                if (SearchTextBox.Text == "")
                    GridView1.DataSourceID = "SqlDataSource16";
                else
                {
                    GridView1.DataSourceID = "SqlDataSource26";
                }
            }
            else if (SearchDropDownList.SelectedValue.Equals("CompanyName"))
            {
                if (SearchTextBox.Text == "")
                    GridView1.DataSourceID = "SqlDataSource16";
                else
                {
                    GridView1.DataSourceID = "SqlDataSource27";
                }
            }
            else if (SearchDropDownList.SelectedValue.Equals("PreferredDay"))
            {
                if ((Date1.Text == "") || (Date2.Text == ""))
                    GridView1.DataSourceID = "SqlDataSource16";
                else
                {
                    GridView1.DataSourceID = "SqlDataSource32";
                }
            }
            else if (SearchDropDownList.SelectedValue.Equals("All"))
            {
                if (SearchTextBox.Text == "")
                    GridView1.DataSourceID = "SqlDataSource16";
                else
                {
                    GridView1.DataSourceID = "SqlDataSource30";
                }
            }
            else
            {
                GridView1.DataSourceID = "SqlDataSource16";
            }

            Label5.Text = "Last";
        }

        protected void Button2_Click(object sender, EventArgs e)
        {

            if (SearchDropDownList.SelectedValue.Equals("PromotionCode"))
            {
                GridView1.DataSourceID = "SqlDataSource13";
            }
            else if (SearchDropDownList.SelectedValue.Equals("OperatorSSE"))
            {
                GridView1.DataSourceID = "SqlDataSource2";
            }
            else if (SearchDropDownList.SelectedValue.Equals("AccountStatus"))
            {
                GridView1.DataSourceID = "SqlDataSource12";
            }
            else if (SearchDropDownList.SelectedValue.Equals("TypeOrg"))
            {
                GridView1.DataSourceID = "SqlDataSource33";
            }
            else if (SearchDropDownList.SelectedValue.Equals("StateName"))
            {
                GridView1.DataSourceID = "SqlDataSource11";
            }
            else if (SearchDropDownList.SelectedValue.Equals("CurrentProvider"))
            {
                GridView1.DataSourceID = "SqlDataSource25";
            }
            else if (SearchDropDownList.SelectedValue.Equals("UserID"))
            {
                if (SearchTextBox.Text == "")
                {
                    GridView1.DataSourceID = "SqlDataSource0";
                }
                else
                {
                    GridView1.DataSourceID = "SqlDataSource15";
                }
            }
            else if (SearchDropDownList.SelectedValue.Equals("FirstName"))
            {
                if (SearchTextBox.Text == "")
                    GridView1.DataSourceID = "SqlDataSource0";
                else
                {
                    GridView1.DataSourceID = "SqlDataSource9";
                }
            }
            else if (SearchDropDownList.SelectedValue.Equals("LastName"))
            {
                if (SearchTextBox.Text == "")
                    GridView1.DataSourceID = "SqlDataSource0";
                else
                {
                    GridView1.DataSourceID = "SqlDataSource10";
                }
            }
            else if (SearchDropDownList.SelectedValue.Equals("Email"))
            {
                if (SearchTextBox.Text == "")
                    GridView1.DataSourceID = "SqlDataSource0";
                else
                {
                    GridView1.DataSourceID = "SqlDataSource14";
                }
            }
            else if (SearchDropDownList.SelectedValue.Equals("Phone"))
            {
                if (SearchTextBox.Text == "")
                    GridView1.DataSourceID = "SqlDataSource0";
                else
                {
                    GridView1.DataSourceID = "SqlDataSource23";
                }
            }
            else if (SearchDropDownList.SelectedValue.Equals("CompanyName"))
            {
                if (SearchTextBox.Text == "")
                    GridView1.DataSourceID = "SqlDataSource0";
                else
                {
                    GridView1.DataSourceID = "SqlDataSource24";
                }
            }
            else if (SearchDropDownList.SelectedValue.Equals("PreferredDay"))
            {
                if ((Date1.Text == "") || (Date2.Text == ""))
                    GridView1.DataSourceID = "SqlDataSource0";
                else
                {
                    GridView1.DataSourceID = "SqlDataSource31";
                }
            }
            else if (SearchDropDownList.SelectedValue.Equals("All"))
            {
                if (SearchTextBox.Text == "")
                    GridView1.DataSourceID = "SqlDataSource0";
                else
                {
                    GridView1.DataSourceID = "SqlDataSource29";
                }
            }
            else
            {
                GridView1.DataSourceID = "SqlDataSource0";
            }

            Label5.Text = "First";
        }

        protected void PageSizeList_SelectedIndexChanged(object sender, EventArgs e)
        {
            GridView1.PageSize = Convert.ToInt32(PageSizeList.SelectedValue);
        }

        protected void Button3_Click(object sender, EventArgs e)
        {
            GridView1.AllowPaging = false;
            GridView1.DataBind();
            Response.Clear();
            Response.AppendHeader("Content-Disposition", "attachment;filename= " + Server.UrlEncode("Export.xls"));
            Response.ContentType = "application/ms-excel";
            this.EnableViewState = false;
            System.Globalization.CultureInfo myCItrad = new System.Globalization.CultureInfo("EN", true);
            System.IO.StringWriter stringWrite = new System.IO.StringWriter(myCItrad);
            System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
            GridView1.RenderControl(htmlWrite);
            Response.Write(stringWrite.ToString());
            Response.End();
            GridView1.AllowPaging = true;
        }

        override public void VerifyRenderingInServerForm(Control control)
        { }

        protected void Button4_Click(object sender, EventArgs e)
        {
            if (DetailsView1.FindControl("FirstName") != null)
            {
                ((TextBox)DetailsView1.FindControl("FirstName")).Text = (String)Session["FirstName"];
                ((TextBox)DetailsView1.FindControl("LastName")).Text = (String)Session["LastName"];
                ((TextBox)DetailsView1.FindControl("CompanyName")).Text = (String)Session["CompanyName"];
                ((TextBox)DetailsView1.FindControl("CompanyABN")).Text = (String)Session["CompanyABN"];
                ((TextBox)DetailsView1.FindControl("Street")).Text = (String)Session["Street"];
                ((TextBox)DetailsView1.FindControl("Suburb")).Text = (String)Session["Suburb"];
                ((TextBox)DetailsView1.FindControl("StateName")).Text = (String)Session["StateName"];
                ((TextBox)DetailsView1.FindControl("Postcode")).Text = (String)Session["Postcode"];
                ((TextBox)DetailsView1.FindControl("Phone")).Text = (String)Session["Phone"];
                ((TextBox)DetailsView1.FindControl("Mobile")).Text = (String)Session["Mobile"];
                ((TextBox)DetailsView1.FindControl("Email")).Text = (String)Session["Email"];
                ((TextBox)DetailsView1.FindControl("Comments")).Text = (String)Session["Comments"];
                ((TextBox)DetailsView1.FindControl("CurrentProvider")).Text = (String)Session["CurrentProvider"];
                ((TextBox)DetailsView1.FindControl("PromotionCode")).Text = (String)Session["PromotionCode"];
                ((TextBox)DetailsView1.FindControl("AdminFee")).Text = (String)Session["AdminFee"];
                ((TextBox)DetailsView1.FindControl("LeadSource")).Text = (String)Session["LeadSource"];
                ((TextBox)DetailsView1.FindControl("TypeOrg")).Text = (String)Session["TypeOrg"];
                ((TextBox)DetailsView1.FindControl("PreferredDay")).Text = (String)Session["PreferredDay"];
                ((TextBox)DetailsView1.FindControl("PreferredTime")).Text = (String)Session["PreferredTime"];
                ((TextBox)DetailsView1.FindControl("TotalSites")).Text = (String)Session["TotalSites"];
                ((TextBox)DetailsView1.FindControl("ElecTotalAnnualSpend")).Text = (String)Session["ElecTotalAnnualSpend"];
                ((TextBox)DetailsView1.FindControl("GasTotalAnnualSpend")).Text = (String)Session["GasTotalAnnualSpend"];
                ((TextBox)DetailsView1.FindControl("TotalAnnualSpend")).Text = (String)Session["TotalAnnualSpend"];
                ((TextBox)DetailsView1.FindControl("AccountStatus")).Text = (String)Session["AccountStatus"];
                ((TextBox)DetailsView1.FindControl("StatusName")).Text = (String)Session["StatusName"];
                ((TextBox)DetailsView1.FindControl("AccountStatusHistory")).Text = (String)Session["AccountStatusHistory"];
                ((TextBox)DetailsView1.FindControl("SourceCode")).Text = (String)Session["SourceCode"];
                ((TextBox)DetailsView1.FindControl("OperatorSSE")).Text = (String)Session["OperatorSSE"];
                ((TextBox)DetailsView1.FindControl("VendorID")).Text = (String)Session["VendorID"];
                ((TextBox)DetailsView1.FindControl("DateConverted")).Text = (String)Session["DateConverted"];
                ((TextBox)DetailsView1.FindControl("MoverSwicher")).Text = (String)Session["MoverSwicher"];
                ((TextBox)DetailsView1.FindControl("RESI_SME")).Text = (String)Session["RESI_SME"];
                ((TextBox)DetailsView1.FindControl("ElectricityConversion")).Text = (String)Session["ElectricityConversion"];
                ((TextBox)DetailsView1.FindControl("GasConversion")).Text = (String)Session["GasConversion"];
                ((TextBox)DetailsView1.FindControl("MoveInDate")).Text = (String)Session["MoveInDate"];
                ((TextBox)DetailsView1.FindControl("ID_Type")).Text = (String)Session["ID_Type"];
                ((TextBox)DetailsView1.FindControl("ID_Number")).Text = (String)Session["ID_Number"];
                ((TextBox)DetailsView1.FindControl("ID_Expiry")).Text = (String)Session["ID_Expiry"];
                ((TextBox)DetailsView1.FindControl("AccountHolderCompanyName")).Text = (String)Session["AccountHolderCompanyName"];
                ((TextBox)DetailsView1.FindControl("FirstAccountHolderTitle")).Text = (String)Session["FirstAccountHolderTitle"];
                ((TextBox)DetailsView1.FindControl("FirstAccountHolderFirstName")).Text = (String)Session["FirstAccountHolderFirstName"];
                ((TextBox)DetailsView1.FindControl("FirstAccountHolderSurname")).Text = (String)Session["FirstAccountHolderSurname"];
                ((TextBox)DetailsView1.FindControl("FirstAccountHolderDOB")).Text = (String)Session["FirstAccountHolderDOB"];
                ((TextBox)DetailsView1.FindControl("SecondAccountHolderTitle")).Text = (String)Session["SecondAccountHolderTitle"];
                ((TextBox)DetailsView1.FindControl("SecondAccountHolderFirstName")).Text = (String)Session["SecondAccountHolderFirstName"];
                ((TextBox)DetailsView1.FindControl("SecondAccountHolderSurname")).Text = (String)Session["SecondAccountHolderSurname"];
                ((TextBox)DetailsView1.FindControl("SecondAccountHolderDOB")).Text = (String)Session["SecondAccountHolderDOB"];
                ((TextBox)DetailsView1.FindControl("ContactTel")).Text = (String)Session["ContactTel"];
                ((TextBox)DetailsView1.FindControl("SecondTel")).Text = (String)Session["SecondTel"];
                ((TextBox)DetailsView1.FindControl("SupplyAddress")).Text = (String)Session["SupplyAddress"];
                ((TextBox)DetailsView1.FindControl("SupplyAddressSuburb")).Text = (String)Session["SupplyAddressSuburb"];
                ((TextBox)DetailsView1.FindControl("SupplyAddressState")).Text = (String)Session["SupplyAddressState"];
                ((TextBox)DetailsView1.FindControl("SupplyAddressPostcode")).Text = (String)Session["SupplyAddressPostcode"];
                ((TextBox)DetailsView1.FindControl("TenantOwner")).Text = (String)Session["TenantOwner"];
                ((TextBox)DetailsView1.FindControl("Elec")).Text = (String)Session["Elec"];
                ((TextBox)DetailsView1.FindControl("Gas")).Text = (String)Session["Gas"];
                ((TextBox)DetailsView1.FindControl("ProductType")).Text = (String)Session["ProductType"];
                ((TextBox)DetailsView1.FindControl("NoOfPeopleInHouse")).Text = (String)Session["NoOfPeopleInHouse"];
                ((TextBox)DetailsView1.FindControl("ConcessionCardType")).Text = (String)Session["ConcessionCardType"];
                ((TextBox)DetailsView1.FindControl("ConcessionCardEntitlement")).Text = (String)Session["ConcessionCardEntitlement"];
                ((TextBox)DetailsView1.FindControl("ConcessionCardNo")).Text = (String)Session["ConcessionCardNo"];
                ((TextBox)DetailsView1.FindControl("ConcessionCardExp")).Text = (String)Session["ConcessionCardExp"];
                ((TextBox)DetailsView1.FindControl("NameOnConcessionCard")).Text = (String)Session["NameOnConcessionCard"];
                ((TextBox)DetailsView1.FindControl("AnyHazards")).Text = (String)Session["AnyHazards"];
                ((TextBox)DetailsView1.FindControl("AnyAccessRequirements")).Text = (String)Session["AnyAccessRequirements"];
                ((TextBox)DetailsView1.FindControl("SpecialInstructionsForAccess")).Text = (String)Session["SpecialInstructionsForAccess"];
                ((TextBox)DetailsView1.FindControl("AdvisedMainSwitchNeedsTurningOff")).Text = (String)Session["AdvisedMainSwitchNeedsTurningOff"];
                ((TextBox)DetailsView1.FindControl("SafetyCertificateRequired")).Text = (String)Session["SafetyCertificateRequired"];
                ((TextBox)DetailsView1.FindControl("ElecStatus")).Text = (String)Session["ElecStatus"];
                ((TextBox)DetailsView1.FindControl("GasStatus")).Text = (String)Session["GasStatus"];
                ((TextBox)DetailsView1.FindControl("Reason")).Text = (String)Session["Reason"];
                ((TextBox)DetailsView1.FindControl("ExistingTRUEnergyCustomer")).Text = (String)Session["ExistingTRUEnergyCustomer"];
                ((TextBox)DetailsView1.FindControl("AdditionalQuestion")).Text = (String)Session["AdditionalQuestion"];
                ((TextBox)DetailsView1.FindControl("SSE_Operator_Feedback")).Text = (String)Session["SSE_Operator_Feedback"];

            }
        }

        protected void Date1_TextChanged(object sender, EventArgs e)
        {

        }

        protected void Date2_TextChanged(object sender, EventArgs e)
        {
            
        }

        protected void Button5_Click(object sender, EventArgs e)
        {
            if (Label10.Text.Equals("None") || Label11.Text.Equals("None") || Label17.Text.Equals("None") || Label18.Text.Equals("None") || Label19.Text.Equals("None"))
            {
                Label10.Text = "Converted";
                Label11.Text = "Not Interested";
                Label17.Text = "Solar";
                Label18.Text = "C&I";
                Label19.Text = "Cannot Quote";

            }
            else{
                Label10.Text = "None";
                Label11.Text = "None";
                Label17.Text = "None";
                Label18.Text = "None"; 
                Label19.Text = "None";
            }
        }

        public void SendMail(String receiver, String subject, String body) 
        { 
            MailMessage msg = new MailMessage();
            msg.To.Add(receiver); 
            msg.From = new MailAddress("Lisa@StreetSmartEnergy.com.au", "Street Smart Energy", System.Text.Encoding.UTF8);
            msg.Subject = subject;
            msg.SubjectEncoding = System.Text.Encoding.UTF8; 
            msg.Body = body;
            msg.BodyEncoding = System.Text.Encoding.UTF8;
            msg.IsBodyHtml = true;
            msg.Priority = MailPriority.High;
            SmtpClient client = new SmtpClient(); 
            client.Host = "localhost"; 
            //object userState = msg; 
            //try
            //{    
                //client.SendAsync(msg, userState); 
                client.Send(msg); 
                //Label14.Text="Success!"; 
            //} 
            //catch (System.Net.Mail.SmtpException )
            //{ 
                //Label14.Text=("Error When Sending Email!"); 
            //}
        }

        public void SendBulkMail(String subject, String body)
        {
            MailMessage msg = new MailMessage();
            for (int i = 0; i < maillist.Count; i++)
            {
                msg.To.Add((String)maillist[i]);
            }           
            msg.From = new MailAddress("Lisa@StreetSmartEnergy.com.au", "Street Smart Energy", System.Text.Encoding.UTF8);
            msg.Subject = subject;
            msg.SubjectEncoding = System.Text.Encoding.UTF8;
            msg.Body = body;
            msg.BodyEncoding = System.Text.Encoding.UTF8;
            msg.IsBodyHtml = true;
            msg.Priority = MailPriority.High;
            SmtpClient client = new SmtpClient();
            client.Host = "localhost";
            //object userState = msg; 
            //try
            //{
                //client.SendAsync(msg, userState); 
                client.Send(msg);
                //Label14.Text = "Success!";
            //}
            //catch (System.Net.Mail.SmtpException)
            //{
            //    Label14.Text = ("Error!");
            //}
        }

        protected void Button6_Click(object sender, EventArgs e)
        {
            if ((TextBox)DetailsView1.FindControl("Email") != null)
            {
                Button6.Visible = false;
                Button7.Visible = true;
                Button8.Visible = true;
                pnlSelectEmail.Visible = true;
                Label14.Text=((TextBox)DetailsView1.FindControl("Email")).Text;
                Label16.Text = "Single";
            }
        }

        protected void Button7_Click(object sender, EventArgs e)
        {
            
            String subject = lblTemplateSubject.Text;
            String body = lblTemplateBody.Text;
            if (Label16.Text.Equals("Single"))
            {
                String receiver = ((TextBox)DetailsView1.FindControl("Email")).Text;
                SendMail(receiver, subject, body);
                Label14.Text = "Success!"; 
            }
            else if (Label16.Text.Equals("Bulk")&&(maillist.Count>0))
            {
                for (int i = 0; i < maillist.Count; i++)
                {
                    SendMail((String)maillist[i], subject, body);
                }
                Label14.Text = "Success!"; 
                //SendBulkMail(subject, body);
            }
            Button6.Visible = true;
            Button7.Visible = false;
            Button8.Visible = false;
            Button9.Visible = true;
            pnlSelectEmail.Visible = false;
            Label16.Text = "";
        }

        protected void ddlEmail_SelectedIndexChanged(object sender, EventArgs e)
        {
            String EmailTemplateName;
            String EmailTemplateSubject;
            String EmailTemplateBody;
            string connectionString=null;
            System.Configuration.ConnectionStringSettings connString = System.Configuration.ConfigurationManager.ConnectionStrings["SQLServer2005DBConnectionString"];
            if (null != connString)
                connectionString = connString.ConnectionString;
            SqlConnection connection = null;
            try
            {
                connection = new SqlConnection(connectionString);
                connection.Open();
                SqlCommand command;
                SqlDataReader reader;
                command= connection.CreateCommand();
                command.CommandText = "select * from tblEmailTemplate where EmailTemplateID=" + ddlET.SelectedValue;
                reader = command.ExecuteReader();
                reader.Read();
                EmailTemplateName = Convert.ToString(reader["EmailTemplateName"]);
                EmailTemplateSubject = Convert.ToString(reader["EmailTemplateSubject"]);
                EmailTemplateBody = Convert.ToString(reader["EmailTemplateBody"]);
                reader.Close();
                connection.Close();
                lblTemplateName.Text = EmailTemplateName;
                lblTemplateSubject.Text = EmailTemplateSubject;
                lblTemplateBody.Text = EmailTemplateBody;
            }
            catch (Exception)
            {
                if (connection != null)
            {
                connection.Dispose();
            }
        }
        }

        protected void Button8_Click(object sender, EventArgs e)
        {
            Button6.Visible = true;
            Button7.Visible = false;
            Button8.Visible = false;
            pnlSelectEmail.Visible = false;
            Label14.Text = "";
            Label16.Text = "";
        }

        protected void Button9_Click(object sender, EventArgs e)
        {
            String address = "";
            maillist= new ArrayList();
            string connectionString = null;
            System.Configuration.ConnectionStringSettings connString = System.Configuration.ConfigurationManager.ConnectionStrings["SQLServer2005DBConnectionString"];
            if (null != connString)
                connectionString = connString.ConnectionString;
            SqlConnection connection = null;
                connection = new SqlConnection(connectionString);
                connection.Open();
                SqlCommand command;
                SqlDataReader reader;
                command = connection.CreateCommand();
                command.CommandText = "select UserID, Email from tblUser where PromotionCode='" + DropDownList2.SelectedValue + "' order by UserID;";
                reader = command.ExecuteReader();
                while(reader.Read()){
                    if(IsValidEmail(Convert.ToString(reader["Email"])))
                        maillist.Add((Convert.ToString(reader["Email"])).Trim());
                }
                reader.Close();
                connection.Close();
            
            for (int i = 0; i < maillist.Count; i++)
            {
                address = address + maillist[i]+";";
            }
                Label14.Text = address;
                Button6.Visible = false;
                Button7.Visible = true;
                Button8.Visible = true;
                Button9.Visible = false;
                pnlSelectEmail.Visible = true;
                Label16.Text = "Bulk";
        }

        protected void Button10_Click(object sender, EventArgs e)
        {
            String address = "";
            maillist = new ArrayList();
            string connectionString = null;
            System.Configuration.ConnectionStringSettings connString = System.Configuration.ConfigurationManager.ConnectionStrings["SQLServer2005DBConnectionString"];
            if (null != connString)
                connectionString = connString.ConnectionString;
            SqlConnection connection = null;
            connection = new SqlConnection(connectionString);
            connection.Open();
            SqlCommand command;
            SqlDataReader reader;
            command = connection.CreateCommand();
            command.CommandText = "select * from tblUser where not(statusname='Converted' or statusname='Solar' or statusname='C&I');";
            reader = command.ExecuteReader();
            while (reader.Read())
            {
                if (IsValidEmail(Convert.ToString(reader["Email"])))
                    maillist.Add((Convert.ToString(reader["Email"])).Trim());
            }
            reader.Close();
            connection.Close();

            for (int i = 0; i < maillist.Count; i++)
            {
                address = address + maillist[i] + ";";
            }
            Label14.Text = address;
            Button6.Visible = false;
            Button7.Visible = true;
            Button8.Visible = true;
            Button9.Visible = false;
            pnlSelectEmail.Visible = true;
            Label16.Text = "Bulk";
        }

        protected void UpdateButton_Click(object sender, EventArgs e)
        {
            String miss = "";
            if (((TextBox)DetailsView1.FindControl("StatusName")).Text.Equals("Converted"))
            {
                if (((TextBox)DetailsView1.FindControl("TypeOrg")).Text.Equals("RESI"))
                {
                    if(((TextBox)DetailsView1.FindControl("FirstName")).Text.Equals(""))
                        miss = miss + "FirstName \\n";
                    if (((TextBox)DetailsView1.FindControl("LastName")).Text.Equals(""))
                        miss = miss + "LastName \\n";
                    if (((TextBox)DetailsView1.FindControl("Email")).Text.Equals(""))
                        miss = miss + "Email \\n";
                    if (((TextBox)DetailsView1.FindControl("Street")).Text.Equals(""))
                        miss = miss + "Street \\n";
                    if (((TextBox)DetailsView1.FindControl("Suburb")).Text.Equals(""))
                        miss = miss + "Suburb \\n";
                    if (((TextBox)DetailsView1.FindControl("StateName")).Text.Equals(""))
                        miss = miss + "StateName \\n";
                    if (((TextBox)DetailsView1.FindControl("Postcode")).Text.Equals(""))
                        miss = miss + "Postcode \\n";
                    if (((TextBox)DetailsView1.FindControl("Phone")).Text.Equals(""))
                        miss = miss + "Phone \\n";
                    if (((TextBox)DetailsView1.FindControl("CurrentProvider")).Text.Equals(""))
                        miss = miss + "CurrentProvider \\n";
                    if (((TextBox)DetailsView1.FindControl("PromotionCode")).Text.Equals(""))
                        miss = miss + "PromotionCode \\n";
                    if (((TextBox)DetailsView1.FindControl("LeadSource")).Text.Equals(""))
                        miss = miss + "LeadSource \\n";
                    if (((TextBox)DetailsView1.FindControl("TotalSites")).Text.Equals(""))
                        miss = miss + "TotalSites \\n";
                    if (((TextBox)DetailsView1.FindControl("SourceCode")).Text.Equals(""))
                        miss = miss + "SourceCode \\n";
                    if (((TextBox)DetailsView1.FindControl("ProductType")).Text.Equals(""))
                        miss = miss + "ProductType \\n";
                    if (((TextBox)DetailsView1.FindControl("OperatorSSE")).Text.Equals(""))
                        miss = miss + "OperatorSSE \\n";
                    if (((TextBox)DetailsView1.FindControl("DateConverted")).Text.Equals(""))
                        miss = miss + "DateConverted \\n";
                    if (((TextBox)DetailsView1.FindControl("MoverSwicher")).Text.Equals(""))
                        miss = miss + "MoverSwicher \\n";
                    if (((TextBox)DetailsView1.FindControl("MoverSwicher")).Text.Equals("Mover"))
                    {
                        if (((TextBox)DetailsView1.FindControl("MoveInDate")).Text.Equals(""))
                            miss = miss + "MoveInDate \\n";
                    }
                    if (((TextBox)DetailsView1.FindControl("RESI_SME")).Text.Equals(""))
                        miss = miss + "RESI_SME \\n";
                    if (((TextBox)DetailsView1.FindControl("ElectricityConversion")).Text.Equals(""))
                        miss = miss + "ElectricityConversion \\n";
                    if (((TextBox)DetailsView1.FindControl("GasConversion")).Text.Equals(""))
                        miss = miss + "GasConversion \\n";
                    if (((TextBox)DetailsView1.FindControl("ID_Type")).Text.Equals(""))
                        miss = miss + "ID_Type \\n";
                    if (((TextBox)DetailsView1.FindControl("ID_Number")).Text.Equals(""))
                        miss = miss + "ID_Number \\n";
                    if (((TextBox)DetailsView1.FindControl("FirstAccountHolderTitle")).Text.Equals(""))
                        miss = miss + "FirstAccountHolderTitle \\n";
                    if (((TextBox)DetailsView1.FindControl("FirstAccountHolderFirstName")).Text.Equals(""))
                        miss = miss + "FirstAccountHolderFirstName \\n";
                    if (((TextBox)DetailsView1.FindControl("FirstAccountHolderSurname")).Text.Equals(""))
                        miss = miss + "FirstAccountHolderSurname \\n";
                    if (((TextBox)DetailsView1.FindControl("FirstAccountHolderDOB")).Text.Equals(""))
                        miss = miss + "FirstAccountHolderDOB \\n";
                    if (((TextBox)DetailsView1.FindControl("SupplyAddress")).Text.Equals(""))
                        miss = miss + "SupplyAddress \\n";
                    if (((TextBox)DetailsView1.FindControl("SupplyAddressSuburb")).Text.Equals(""))
                        miss = miss + "SupplyAddressSuburb \\n";
                    if (((TextBox)DetailsView1.FindControl("SupplyAddressState")).Text.Equals(""))
                        miss = miss + "SupplyAddressState \\n";
                    if (((TextBox)DetailsView1.FindControl("SupplyAddressPostcode")).Text.Equals(""))
                        miss = miss + "SupplyAddressPostcode \\n";
                    if (((TextBox)DetailsView1.FindControl("TenantOwner")).Text.Equals(""))
                        miss = miss + "TenantOwner \\n";
                    if (((TextBox)DetailsView1.FindControl("Elec")).Text.Equals(""))
                        miss = miss + "Elec \\n";
                    if (((TextBox)DetailsView1.FindControl("Gas")).Text.Equals(""))
                        miss = miss + "Gas \\n";
                    if (((TextBox)DetailsView1.FindControl("ExistingTRUEnergyCustomer")).Text.Equals(""))
                        miss = miss + "ExistingTRUEnergyCustomer \\n";

                    if (((TextBox)DetailsView1.FindControl("PromotionCode")).Text.Equals("GOLFNSW"))
                    {
                        if (((TextBox)DetailsView1.FindControl("GolfClub")).Text.Equals(""))
                            miss = miss + "GolfClub \\n";
                    }

                    if (miss.Equals(""))
                        DetailsView1.UpdateItem(false);
                    else
                    {
                        MessageBox("The following fields must be completed:\\n" + miss);
                    }
                }

                else if (((TextBox)DetailsView1.FindControl("TypeOrg")).Text.Equals("SME"))
                {
                    if (((TextBox)DetailsView1.FindControl("CompanyName")).Text.Equals(""))
                        miss = miss + "CompanyName \\n";
                    if (((TextBox)DetailsView1.FindControl("CompanyABN")).Text.Equals(""))
                        miss = miss + "CompanyABN \\n";
                    if (((TextBox)DetailsView1.FindControl("FirstName")).Text.Equals(""))
                        miss = miss + "FirstName \\n";
                    if (((TextBox)DetailsView1.FindControl("LastName")).Text.Equals(""))
                        miss = miss + "LastName \\n";
                    if (((TextBox)DetailsView1.FindControl("Email")).Text.Equals(""))
                        miss = miss + "Email \\n";
                    if (((TextBox)DetailsView1.FindControl("Street")).Text.Equals(""))
                        miss = miss + "Street \\n";
                    if (((TextBox)DetailsView1.FindControl("Suburb")).Text.Equals(""))
                        miss = miss + "Suburb \\n";
                    if (((TextBox)DetailsView1.FindControl("StateName")).Text.Equals(""))
                        miss = miss + "StateName \\n";
                    if (((TextBox)DetailsView1.FindControl("Postcode")).Text.Equals(""))
                        miss = miss + "Postcode \\n";
                    if (((TextBox)DetailsView1.FindControl("Phone")).Text.Equals(""))
                        miss = miss + "Phone \\n";
                    if (((TextBox)DetailsView1.FindControl("CurrentProvider")).Text.Equals(""))
                        miss = miss + "CurrentProvider \\n";
                    if (((TextBox)DetailsView1.FindControl("PromotionCode")).Text.Equals(""))
                        miss = miss + "PromotionCode \\n";
                    if (((TextBox)DetailsView1.FindControl("LeadSource")).Text.Equals(""))
                        miss = miss + "LeadSource \\n";
                    if (((TextBox)DetailsView1.FindControl("TotalSites")).Text.Equals(""))
                        miss = miss + "TotalSites \\n";
                    if (((TextBox)DetailsView1.FindControl("SourceCode")).Text.Equals(""))
                        miss = miss + "SourceCode \\n";
                    if (((TextBox)DetailsView1.FindControl("ProductType")).Text.Equals(""))
                        miss = miss + "ProductType \\n";
                    if (((TextBox)DetailsView1.FindControl("OperatorSSE")).Text.Equals(""))
                        miss = miss + "OperatorSSE \\n";
                    if (((TextBox)DetailsView1.FindControl("DateConverted")).Text.Equals(""))
                        miss = miss + "DateConverted \\n";
                    if (((TextBox)DetailsView1.FindControl("MoverSwicher")).Text.Equals(""))
                        miss = miss + "MoverSwicher \\n";
                    if (((TextBox)DetailsView1.FindControl("MoverSwicher")).Text.Equals("Mover"))
                    {
                        if (((TextBox)DetailsView1.FindControl("MoveInDate")).Text.Equals(""))
                            miss = miss + "MoveInDate \\n";
                    }
                    if (((TextBox)DetailsView1.FindControl("RESI_SME")).Text.Equals(""))
                        miss = miss + "RESI_SME \\n";
                    if (((TextBox)DetailsView1.FindControl("ElectricityConversion")).Text.Equals(""))
                        miss = miss + "ElectricityConversion \\n";
                    if (((TextBox)DetailsView1.FindControl("GasConversion")).Text.Equals(""))
                        miss = miss + "GasConversion \\n";
                    if (((TextBox)DetailsView1.FindControl("SupplyAddress")).Text.Equals(""))
                        miss = miss + "SupplyAddress \\n";
                    if (((TextBox)DetailsView1.FindControl("SupplyAddressSuburb")).Text.Equals(""))
                        miss = miss + "SupplyAddressSuburb \\n";
                    if (((TextBox)DetailsView1.FindControl("SupplyAddressState")).Text.Equals(""))
                        miss = miss + "SupplyAddressState \\n";
                    if (((TextBox)DetailsView1.FindControl("SupplyAddressPostcode")).Text.Equals(""))
                        miss = miss + "SupplyAddressPostcode \\n";
                    if (((TextBox)DetailsView1.FindControl("TenantOwner")).Text.Equals(""))
                        miss = miss + "TenantOwner \\n";
                    if (((TextBox)DetailsView1.FindControl("Elec")).Text.Equals(""))
                        miss = miss + "Elec \\n";
                    if (((TextBox)DetailsView1.FindControl("Gas")).Text.Equals(""))
                        miss = miss + "Gas \\n";
                    if (((TextBox)DetailsView1.FindControl("ExistingTRUEnergyCustomer")).Text.Equals(""))
                        miss = miss + "ExistingTRUEnergyCustomer \\n";

                    if (((TextBox)DetailsView1.FindControl("PromotionCode")).Text.Equals("GOLFNSW"))
                    {
                        if (((TextBox)DetailsView1.FindControl("GolfClub")).Text.Equals(""))
                            miss = miss + "GolfClub \\n";
                    }

                    if (miss.Equals(""))
                        DetailsView1.UpdateItem(false);
                    else
                    {
                        MessageBox("The following fields must be completed:\\n" + miss);
                    }
                }
                else if (((TextBox)DetailsView1.FindControl("TypeOrg")).Text.Equals("C&I"))
                {
                    DetailsView1.UpdateItem(false);
                }
                else
                {
                    MessageBox("TypeOrg must be completed:\\n");
                }
            }
            else
                DetailsView1.UpdateItem(false);
        }

        public static bool IsValidEmail(string email)
		{
            return Regex.IsMatch(email, RegexComm.REG_EMAIL);
		}

        private void MessageBox(string message)
        {
            if (!string.IsNullOrEmpty(message))
            {
                this.ClientScript.RegisterClientScriptBlock(this.GetType(), "alt1", "alert('"+message+"');", true);
            }
        }


        private string UserCap(string username)
        {
            string str1 = username.Substring(0, 1);
            string str2 = username.Substring(1, username.Length - 1);
            return str1.ToUpper() + str2;
        }
    }
}